﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-09-26 14:34:01
 * 功能：地图相关数据
**************************************************************************************/

using MessagePack;
using System.Collections.Generic;

public partial class GameDataModel
{
    public Map InitMap()
    {
        var cfg = BaseDataMgr.Instance.Cfg.counties;
        Map map = new Map();
        map.countries = new Dictionary<string, Country>(cfg.Count);
        for (int i = 0; i < cfg.Count; i++)
        {
            var countryCfg = cfg[i];
            Country country = new Country();
            country.name = countryCfg.name;
            country.isUnlocked = countryCfg.isUnlock;
            if (countryCfg.cities != null)
            {
                country.cities = new Dictionary<string, City>(countryCfg.cities.Count);
                for (int j = 0; j < countryCfg.cities.Count; j++)
                    country.cities.Add(countryCfg.cities[j].name, new City { name = countryCfg.cities[j].name, countryName = country.name });
            }
            country.unlockedCities = new List<string>();
            map.countries.Add(country.name, country);
        }

        // 设置进度
        map.currentCountry = cfg[0].name;
        map.currentCity = cfg[0].cities[0].name;

        return map;
    }

    // 单个关卡数据
    [MessagePackObject]
    public class Map
    {
        [Key(0)] public Dictionary<string, Country> countries;
        [Key(1)] public string currentCountry;
        [Key(2)] public string currentCity;

        public Country this[string name]
        {
            get
            {
                countries.TryGetValue(name, out var reuslt);
                return reuslt;
            }
        }
    }

    // 单个国家
    [MessagePackObject]
    public class Country
    {
        [Key(0)] public string name;
        [Key(1)] public bool isUnlocked;
        [Key(2)] public Dictionary<string, City> cities;
        [Key(3)] public List<string> unlockedCities;

        public City this[string name]
        {
            get
            {
                cities.TryGetValue(name, out var reuslt);
                return reuslt;
            }
        }
    }

    // 单个城市
    [MessagePackObject]
    public class City
    {
        [Key(0)] public string name;
        [Key(1)] public string countryName;
        [Key(2)] public bool isUnlocked;
        [Key(3)] public List<ImgData> imgInfos;
    }

    [MessagePackObject]
    public class ImgData
    {
        [Key(0)] public AssetInfo assetsInfo;           // 资源信息;
        [Key(1)] public int lookAdCount;                // 观看广告次数
    }
}